package com.lsy.weizhi2.customview;

import android.content.Context;
import android.content.res.TypedArray;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lsy.weizhi2.R;

/**
 * Created by 嗨哟 on 2017/3/13.
 */
public class HomeBottomItem extends LinearLayout {
    private Context context;
    private String name;
    private int image,name_color;
    private ImageView home_bottom_image;
    private TextView home_bottom_name;
    private View view;
    public HomeBottomItem(Context context, AttributeSet attrs) {
        super(context, attrs);
        view=LayoutInflater.from(context).inflate(R.layout.home_bottom_item,this,true);
        TypedArray typedArray=context.obtainStyledAttributes(attrs,R.styleable.HomeBottomItem);
        name=typedArray.getString(R.styleable.HomeBottomItem_name);
        image=typedArray.getResourceId(R.styleable.HomeBottomItem_image,0);
        name_color=typedArray.getResourceId(R.styleable.HomeBottomItem_name_color,0);
        typedArray.recycle();
    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        home_bottom_image= (ImageView) view.findViewById(R.id.home_bottom_image);
        home_bottom_name= (TextView) view.findViewById(R.id.home_bottom_name);
        if(!TextUtils.isEmpty(name)){
            home_bottom_name.setText(name);
        }
        if(image!=0){
            home_bottom_image.setImageResource(image);
        }
        if(name_color!=0){
            home_bottom_name.setTextColor(name_color);
        }
    }

    public void Change(int image,boolean click){
        home_bottom_image.setImageResource(image);
        if(click){
            home_bottom_name.setTextColor(getResources().getColor(R.color.clicked_ok));
        }else{
            home_bottom_name.setTextColor(getResources().getColor(R.color.clicked_no));
        }
    }

}
